package servlet;
/*
用户登录时，将用户的登录数据添加到session域中
 */
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

public class SetSession  extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("SetSession服务器接收到LoggingServlet端的请求");
        //1.从request域中获取已经登录了的用户名
         boolean logging = (boolean) req.getAttribute("logging");
        String mapJson = (String)req.getAttribute("mapJson");
        System.out.println("已存"+ logging);
//        String password = (String) req.getAttribute("password");
        //将需要共享的数据存在session中

        //2.获取到session对象
        HttpSession session = req.getSession();

        //3.通过session对象进行数据存入
        session.setAttribute("logging",logging);

        resp.getWriter().println(mapJson);

    }
}
